//#region 本地存储的演示
let txtInfo = document.getElementById('txtInfo');
let btnSave = document.getElementById('btnSave');

txtInfo.value = localStorage.getItem('huhuiyu.top.info.demo');

btnSave.addEventListener('click', () => {
  // 保存信息到本地存储
  localStorage.setItem('huhuiyu.top.info.demo', txtInfo.value);
  alert('保存成功');
});

//#endregion

//#region token的演示
import { ajax } from './ajax.js';
let btnToken = document.getElementById('btnToken');
let preToken = document.getElementById('preToken');

btnToken.addEventListener('click', () => {
  ajax.get('/token', {}, (data) => {
    preToken.innerHTML = JSON.stringify(data, null, 2);
  });
});

//#endregion

//#region 图片验证码演示
let imgCode = document.getElementById('imgCode');
let aCode = document.getElementById('aCode');

// 获取图片验证码
function getImgCode() {
  ajax.post('/tool/getImageCode', {}, (data) => {
    if (data.success) {
      imgCode.setAttribute('src', data.message);
    } else {
      alert(data.message);
    }
  });
}

imgCode.addEventListener('click', getImgCode);
aCode.addEventListener('click', getImgCode);

getImgCode();

//#endregion
